<template>
  <div>
    <el-table :data="recordForm">
      <el-table-column label="学生姓名" align="center" prop="studentName"/>
      <el-table-column label="是否完成" align="center" prop="isPass">
        <template v-slot="scope">
          <el-radio v-model="scope.row.isPass" :label="false">否</el-radio>
          <el-radio v-model="scope.row.isPass" :label="true">是</el-radio>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark">
        <template v-slot="scope">
          <el-input v-model="scope.row.remark" placeholder="备注"></el-input>
        </template>
      </el-table-column>
    </el-table>

    <div style="text-align: center;margin-top: 10px;">
      <el-button type="primary" @click="onSubmit" :loading="submitLoading">提 交</el-button>
    </div>
  </div>
</template>


<script>
import { getClassroomTestRecord,updateTestRecord } from '@/api/exam/classroomTest'

export default {
  name : "editTestScore",
  props: ["testId","classId"],
  data() {
    return {
      submitLoading : false, // 遮罩层
      recordForm : [], //成绩数据
    }
  },
  created() {
    //根据班级id和测试id查询学生测试记录
    getClassroomTestRecord(this.classId,this.testId).then(res=> {
      this.recordForm = res.data.map(item => ({
        ...item,
        isPass: item.isPass || false       // 使用空值合并运算符设置默认值
      }));
    })
  },
  methods : {
    onSubmit() {
      this.submitLoading = true;
      updateTestRecord(this.testId,this.recordForm).then(()=> {
        this.submitLoading = false;
        this.$message.success('保存成功！');
        this.$emit('editScoreSuccess');
      })
    }
  }
}
</script>

<style scoped>

</style>
